/*
 * @Author: xyf
 * @Date: 2021-06-29 10:57:02
 * @LastEditTime: 2021-07-12 18:09:11
 * @LastEditors: xyf
 * @Description: 示例
 */

import storage from '@/utils/storage'
import { sampleBackstage } from '@/api/sample'

const state = () => {
  token: storage.getItem('token') || ''
}

const mutations = {
  SET_TOKEN: (state, data) => {
    storage.setItem('token', data)
    state.token = data
  }
}

const actions = {
  login({ commit }) {
    return new Promise((resolve) => {
      sampleBackstage().then((res) => {
        commit('SET_TOKEN', res.token)
        resolve(res)
      })
    })
  }
}

export default {
  state,
  mutations,
  actions,
  namespaced: true
}
